﻿#include "GLLInc.h"
#include "GLLSineDecline.h"

namespace GLL
{
	namespace Math
	{
		//-------------------------------------------
		void SineDecline::Set( float Amp, float W, float TotalTime )
		{
			_ampNow = _amp = Amp;
			_w = W;
			_totalTime = TotalTime;

			_timePassed = 0;
			_finished = false;
		}

		//-------------------------------------------
		float SineDecline::GetValue( float t )
		{
			if(_finished) return _t0Value;

			_timePassed += t;
			if(_timePassed > _totalTime)_timePassed = _totalTime;
			float timeRemain = _totalTime - _timePassed;
			timeRemain = timeRemain / _totalTime;

			float val = std::sin(_w * _timePassed);
			_value = _ampNow * val + _t0Value;
			_ampNow = (_amp * timeRemain);

			if( timeRemain <= 0)
			{
				_finished = true;
				return _t0Value;
			}

			return _value;
		}

	};
};
